﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fis.Service.Forms
{
    public partial class VersionForm : BaseForm
    {
        public VersionForm()
        {
            InitializeComponent();
        }

        public override void InitializeBinding()
        {
            Fis.Win.Utils.UIUtils.ClearBindings(layoutControl1);
            Fis.Win.Utils.UIUtils.TagBindings(layoutControl1, ViewModel["data"]);
        }

        public override void InitializeViewUI()
        {
            bar2.Visible = false;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Validate();
            ViewModel["Action"] = "set";
            if (string.IsNullOrEmpty(timeEdit1.Text.Trim()))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("新版本发布包不能为空");
            }
            ViewModel["version"] = Agile.Engine.Utils.ZipUtils.Zip(System.IO.File.OpenRead(timeEdit1.Text));

            if (ViewProvider.ExecuteUpdate(ViewModel))
            {
                Close();
                return;
            }
        }

        private void timeEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            using (var f = new OpenFileDialog())
            {
                f.Filter = "Fis 更新包 | *.xap";
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var d = ViewModel["data"] as DataTable;
                    timeEdit1.Text = f.FileName;
                    d.Rows[0]["FXTRA2"] = f.SafeFileName.Substring(0, f.SafeFileName.Length - 4);
                }
            }
        }
    }
}
